<%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录页</title>


    <script type="text/javascript" src="/js/jquery-3.4.1.min.js"></script>

    <style type="text/css">
        body {
            background-color: #0b5c;
            text-align: center;
        }

        .lp-login {
            position: absolute;
            width: 500px;
            height: 300px;
            top: 50%;
            left: 50%;
            margin-top: -250px;
            margin-left: -250px;
            background: #fff;
            border-radius: 4px;
            box-shadow: 0 0 10px #12a591;
            padding: 57px 50px 35px;
            box-sizing: border-box
        }


        .lp-login .submitBtn {
            display: block;
            text-decoration: none;
            height: 48px;
            width: 150px;
            line-height: 24px;
            font-size: 16px;
            color: #fff;
            text-align: center;
            background-image: -webkit-gradient(linear, left top, right top, from(#09cb9d), to(#02b389));
            background-image: linear-gradient(90deg, #09cb9d, #02b389);
            border-radius: 3px
        }


        input[type='text'] {
            height: 30px;
            width: 250px;
        }

        input[type='password'] {
            height: 30px;
            width: 250px;
        }

        span {
            font-style: normal;
            font-variant-ligatures: normal;
            font-variant-caps: normal;
            font-variant-numeric: normal;
            font-variant-east-asian: normal;
            font-weight: normal;
            font-stretch: normal;
            font-size: 16px;
            line-height: 48px;
            font-family: "Hiragino Sans GB", "Microsoft Yahei", SimSun, Arial, "Helvetica Neue", Helvetica, serif;
        }
    </style>

    <script>
        $(function () {

            $("#loginBtn").bind("click", function () {
                var userName = $("#userName").val();
                var password = $("#password").val();
                if (userName == null || $.trim(userName).length === 0) {
                    alert("必须输入用户名~~~");
                    return;
                }
                if (password == null || $.trim(password).length === 0) {
                    alert("必须输入密码~~~");
                    return;
                }

                $.ajax({
                    url: '/v1/account/login',
                    type: 'POST',
                    contentType: 'application/json;charset=utf-8',//请求数据类型
                    data: JSON.stringify({
                        "userName": userName.trim(),
                        "password": password.trim()
                    }),
                    dataType: 'json',
                    success: function (data) {
                        console.log(data);
                        if ("0000" === (data.code) && true === data.success) {
                            if (true === data.login) {//登录成功
                                window.location.href = "index.jsp"
                            } else {
                                alert("用户名或密码不对~~~")
                            }
                        } else {
                            alert(data.msg);
                        }
                    }
                })
            })
        })
    </script>


</head>
<body>
<div class="login">
    <table class="lp-login">
        <tr>
            <td align="right"><span>用户名</span></td>
            <td align="center">
                <label for="userName"></label>
                <input type="text" id="userName" name="userName" placeholder="请输入用户名..." required/>
            </td>
        </tr>
        <tr>
            <td align="right"><span>密&nbsp;&nbsp;&nbsp;码</span></td>
            <td align="center">
                <label for="password"></label>
                <input type="password" id="password" name="password" placeholder="请输入密码..." required/>
            </td>
        </tr>
        <tr align="center">
            <td colspan="2">
                <a href="javasrcipt:void(0)" id="loginBtn" class="submitBtn"><span>登&nbsp;&nbsp;&nbsp;录</span></a>
            </td>
        </tr>
    </table>
</div>


</body>
</html>
